/* 我的分公司二审 */
<template>
  <div>
    <Card :bordered="false">
      <p slot="title">二审</p>
      <MyTrialTab :info="info" />
      <table id="Fgsershen" style="margin-bottom: 20px" width='100%' border="1" cellspacing="0" cellpadding="0">
        <tr>
          <th colspan="4">
            二审单
          </th>
        </tr>
        <tr>
          <td width="25%">
            二审人员
          </td>
          <td width="25%" class="sizeStyle">{{info.Audit2}}</td>
          <td width="25%">
            二审时间
          </td>
          <td width="25%" class="sizeStyle">
            {{this.$moment().format('YYYY-MM-DD')}}
          </td>
        </tr>
        <tr>
          <td colspan="4">
            <div style="width:99%;margin:auto;height:100%;">
              <Table highlight-row border ref="selection" :columns="ershenColumns" :data="info.Ershen" :loading="ershenLoading"
                @on-row-click="getIndex"></Table>
              <Row>
                <Col span="24" style="text-align: center;padding:10px">
                <Button type="primary" @click="inputAdd('Ershen')">添加</Button>
                <Button type="error" @click="inputRemove('Ershen')">删除</Button>
                </Col>
              </Row>
            </div>
          </td>
        </tr>
        <tr>
          <td>
            报告（正文、附图、附件、附表）
          </td>
          <td colspan="3">
            <Button v-if="info.doc!=undefined&&info.doc.ProjectEnvOverview!='undefined'?true:false" :disabled='ProjectEnvOverview!=""?false:true'  :to="ProjectEnvOverview" target='_blank' style="float:left;margin-left:50px">下载</Button>
            <Upload with-credentials :before-upload="upLoadFun" :data='imgUpload' :action="shishi" ref="uploadButton">
              <Button>上传</Button>
            </Upload>
            <!-- <Upload action="//jsonplaceholder.typicode.com/posts/">
              <Button>上传</Button>
            </Upload> -->
          </td>
        </tr>
      </table>
      <Row style="margin-top: 10px">
        <Col span="24" style="text-align:right;">
        <Button type="primary" @click="submit(2)">发送意见</Button>
        </Col>
      </Row>
    </Card>
  </div>
</template>
<script>
  import libs from "../../../libs/uploads";
  export default {
    data() {
      return {
        shishi:'',
        imgUpload: {
          Id: this.$route.query.ProjectId,
          Key: 'ImgUrl'
        },
        info: {},
        ershenLoading: true,
        ershenColumns: [{
            align: "center",
            title: "序号",
            type: "index",
            width: 80
          },
          {
            align: "center",
            title: "二审意见",
            key: "AuditOpinion",
            render: (h, {
              row,
              index
            }) => {
              return h("Input", {
                props: {
                  type: "textarea",
                  autosize:true,
                  value: row.AuditOpinion
                },
                on: {
                  "on-blur": val => {
                    this.info.Ershen[index].AuditOpinion = val.target.value;
                  }
                }
              });
            }
          }
        ],
        query: [],
        ProjectEnvOverview: '',
        proType: 0,
        outTime: 0,
      };
    },
    mounted() {
      let query = this.$route.query;
      this.query = query;
      this.findByProject(query.ProjectId, query.Atype);
      this.shishi = libs.uploads();
    },
    methods: {
      //点击添加意见
      inputAdd(type) {
        // this.info[type].push({});
        this.info[type].push({AuditTime:new Date().getTime()});
      },
      inputRemove(type) {
        this.info[type].splice(this.allIndex, 1);
        console.log(this.info[type] + ' 被删除了')
      },
      getIndex(data, index, event) {
        this.allIndex = index;
      },
      //获取当前项目
      findByProject(ProjectId, Atype) {
        // axios.get("/audit/findByProject", {
        this.$post("audit.findByProject", {
              Atype,
              ProjectId
          })
          .then(res => {
            this.getDownInfo()
            this.imgUpload.Name = '二审' + 1 + '批'
            this.info = res;
            this.ershenLoading = false;
            if(res.Stats == '审核中'){
              this.proType = 1
            }
          });
      },
      getDownInfo(){
        axios.post("wechatpublic/findImg",{
          Id:this.$route.query.ProjectId
        }).then((res)=>{
          if(this.info.Stats == '未提交'){
            this.ProjectEnvOverview =''
          }else{
            for(var i=0;i<res.data.length;i++){
              if(res.data[i].Status == '二审'){
                this.ProjectEnvOverview = res.data[i].ImgUrl
              }
            }
          }
        })
      },
      upLoadFun(){
        this.$refs.uploadButton.clearFiles()
        if(this.proType != 1){
          this.$Message.warning('审核未开始，无法上传文件')
          return false
        }
      },
      submit(type) {
        if(this.outTime == 0){
          this.outTime = 1
          var bl = false;
          setTimeout(()=>{this.outTime = 0},5000)
          let query = this.query;
          let AuditReplyLists = this.info.Ershen;
          AuditReplyLists.map(i=>{
            if(i.AuditOpinion && i.AuditOpinion != ''){
              
            }else{
              bl = true
            }
          })
          if(bl){
            this.outTime = 0
            alert('请填写完整意见后，再发送意见！')
            return
          }
          var dataArr = Object.keys(AuditReplyLists).length <=0 ? [] : '123'
          for (let val of AuditReplyLists) {
            val["AuditId"] = query.Id;
          }
          axios.get("/audit/isAuditb", {
            params: {
              ProjectId: query.ProjectId,
              Btype: query.Atype,
              OK: 1,
              Save: type,
              AuditReplyLists: dataArr,
            }
          }).then(res => {
            let title = res._MESSAGE;
            if (res._STATUS == 1) {
              // if (Object.keys(AuditReplyLists).length <= 0) {
              //   this.$Modal.error({
              //     title: "点击添加请输入意见"
              //   });
              // }
              this.$Modal.success({
                title: title
              });
              social({
                method: 'post',
                url: '/info/notice',
                params: {
                  content: this.info.ProjectName +'项目二审工程师提出审核意见，请尽快进行修改！',
                  app_name: '环评管控系统',
                  app: 'eao',
                  type: this.info.StaffNamesId + '',
                  uid: -1
                },
                }).then((res)=>{
                  console.log(res)
                }).catch((err)=>{
                  console.log(err)
              })
              axios
                .post("/auditreply/saveOrUpdateM", {
                  AuditReplyLists:JSON.stringify(AuditReplyLists),
                  ProjectId: query.ProjectId,
                  Atype: query.Atype,
                  Aoc: '2',
                  Save: type
                })
                .then(res => {
                  // 发送成功后跳转到正在审核页面
                  this.$router.push({name: "myProjectCheck"})
                })
                .catch(err => {
                  this.$Modal.error({
                    title: "发送失败"
                  });
                });
            } else {
              this.$Modal.error({
                title: title + "：等待业务人员提交"
              });
            }
          });
        }else{
          console.log('别点了老铁')
        }
      }
    }
  };
</script>
<style lang="less" scoped>
  #Fgsershen {
    .ivu-input {
      border: none !important;
      height: 30px;

      input {
        outline: medium;
      }
    }
  }
  /deep/ textarea.ivu-input {
    font-size: 12px;
  }
  .sizeStyle {
    font-size:12px;
  }
</style>